﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Ebiz.libs;
using System.Web.Script.Services;
using System.Web.Services;
using System.Data.OleDb;
using System.IO;


namespace Ebiz
{
    public partial class Claims : System.Web.UI.Page
    {
        public string ErrMsg = "";
        DataTable dtGridView = new DataTable();
        string sortExpression = string.Empty;
        public string path = string.Empty;

        /// <summary>
        /// Get Virtual Path
        /// </summary>
        /// <returns></returns>
        public static string GetVirtualPath()
        {
            string url = HttpContext.Current.Request.Url.AbsoluteUri.Remove(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("Claims"));
            return url;
        }

        /// <summary>
        /// Loag Gridview from xml file
        /// </summary>
        public void LoadDataGrid()
        {
            string path = Server.MapPath("~/images/upload/");
            DataTable dt = new DataTable();
            HttpCookie cookie = Request.Cookies["iddata"];
            if (cookie != null)
            {
                string filename = "claims-" + cookie.Value + ".xml";
                if (File.Exists(path + filename))
                {
                    dt.ReadXml(path + filename);
                    dt.Columns.Remove("IDData");
                    gridviewResult.DataSource = dt;
                    gridviewResult.DataBind();
                    gridviewResult.PageIndex = 0;
                }
            }
        }

        /// <summary>
        /// Load Page Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataGrid();
            }
        }

        /// <summary>
        /// Paging Gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gridviewResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridviewResult.PageIndex = e.NewPageIndex;
            LoadDataGrid();
        }

        /// <summary>
        /// Sorting Gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gridviewResult_Sorting(object sender, GridViewSortEventArgs e)
        {
            sortExpression = e.SortExpression + " " + "ASC";
            LoadDataGrid();
        }
    }
}